package service

import (
	"context"

	userinfo "gitee.com/hust-ideas/little-genius-backend/dal/db/user"
	model "gitee.com/hust-ideas/little-genius-backend/model"
)

func (s *ServiceContext) UserProfileUpdatePut(req model.UserProfileUpdatePutReq, c context.Context) (resp *model.UserProfileUpdatePutResp, err error) {
	resp = &model.UserProfileUpdatePutResp{}
	uID := req.UserInfo.Id
	u0, err := s.Model.UserModel.FindOne(c, uID)
	if err != nil {
		return nil, err
	}
	// 更新用户信息
	user := userinfo.User{
		ID:        u0.ID,
		UPassword: u0.UPassword,
		UEmail:    req.UserInfo.Email,
		UName:     req.UserInfo.Username,
		CreatedAt: u0.CreatedAt,
	}
	err = s.Model.UserModel.Update(c, &user)
	if err != nil {
		return nil, err
	}
	return
}
